﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EquipmentConfig.Class;

namespace EquipmentConfig
{
    public partial class PassWord : Form
    {
        MainForm mf;

        public PassWord(MainForm mainForm)
        {
            InitializeComponent();
            mf = mainForm;
        }

        private void PassWord_Load(object sender, EventArgs e)
        {
            cbbType.Properties.Items.AddRange(Common.UserInfo);
            cbbType.SelectedIndex = 0;
        }

        /// <summary>
        /// 确定
        /// </summary>
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtPassWord.Text.Trim() == string.Empty)
            {
                Messages.ShowAlertDialog("请输入密码!", false);
                return;
            }

            string strPassWord = Security.EncryptDES(txtPassWord.Text.Trim(), Security.EncryptKey);
            if (cbbType.SelectedIndex == 0)
            {
                if (strPassWord != Program.keyValue1)
                {
                    Messages.ShowAlertDialog("管理员密码错误!!输入密码：" + txtPassWord.Text.Trim() + ",设备密码：" + Security.DecryptDES(Program.keyValue1, Security.EncryptKey), false);
                    return;
                }
            }

            if (cbbType.SelectedIndex == 1)
            {
                if (strPassWord != Program.keyValue2)
                {
                    Messages.ShowAlertDialog("超级管理员密码错误!输入密码："+ txtPassWord.Text.Trim() + ",设备密码：" + Security.DecryptDES(Program.keyValue2, Security.EncryptKey), false);
                    return;
                }
            }

            mf.paraConfig.InitShowControl(cbbType.SelectedIndex + 1);
            this.Close();
        }

        private void PassWord_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Dispose();
        }
    }
}
